﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UtilZ.Dotnet.Ex.Model;

namespace WinFormApp
{
    public partial class FTestBindingCollection : Form, ICollectionOwner
    {
        public FTestBindingCollection()
        {
            InitializeComponent();
        }

        private BindingCollection<TestItem> _collection;
        private void FTestBindingCollection_Load(object sender, EventArgs e)
        {
            this._collection = new BindingCollection<TestItem>(this);
            this._collection.Add(new TestItem("张三", 50));
            this._collection.Add(new TestItem("李四", 30));
            this._collection.Add(new TestItem("王五", 100));
            this._collection.Add(new TestItem("陈六", 25));
            dataGridView1.DataSource = _collection.DataSource;
        }

        private class TestItem
        {
            public string Name { get; private set; }

            public byte Value { get; private set; }

            public TestItem()
            {

            }

            public TestItem(string name, byte value)
            {
                this.Name = name;
                this.Value = value;
            }
        }
    }
}
